import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true,
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
    ],
  },
  {
     path: "/profile",
     component: Layout,
     redirect: "/profile/notice",
     name: "profile",
     children:[
      {
        path: "notice",
        name: "notice",
        component: () => import("@/views/inform/info.vue"),
        meta: { title: "通知中心"},
        hidden: true,
      }
    ]
  },
  {
    path: "/user",
    component: Layout,
    redirect: "/user/vipManagement",
    name: "user",
    meta: { title: "用户管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "vipManagement",
        name: "vipManagement",
        component: () => import("@/views/user/vipManagement"),
        meta: { title: "会员管理" },
      },
      {
        path: "homeAddress",
        name: "homeAddress",
        component: () => import("@/views/user/homeAddress"),
        meta: { title: "收货地址" },
      },
      {
        path: "collect",
        name: "collect",
        component: () => import("@/views/user/collect"),
        meta: { title: "会员收藏" },
      },
      {
        path: "footprint",
        name: "footprint",
        component: () => import("@/views/user/footprint"),
        meta: { title: "会员足迹" },
      },
      {
        path: "search",
        name: "search",
        component: () => import("@/views/user/search"),
        meta: { title: "搜索历史" },
      },
      {
        path: "feedback",
        name: "feedback",
        component: () => import("@/views/user/feedback"),
        meta: { title: "意见反馈" },
      },
    ],
  },
  {
    path: "/sopping",
    component: Layout,
    redirect: "/sopping/district",
    name: "sopping",
    meta: { title: "商场管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "district",
        name: "district",
        component: () => import("@/views/sopping/district"),
        meta: { title: "行政区域" },
      },
      {
        path: "brand",
        name: "brand",
        component: () => import("@/views/sopping/brand"),
        meta: { title: "品牌制造商" },
      },
      {
        path: "classify",
        name: "classify",
        component: () => import("@/views/sopping/classify"),
        meta: { title: "商品类目" },
      },
      {
        path: "orderform",
        name: "orderform",
        component: () => import("@/views/sopping/orderForm"),
        meta: { title: "订单管理" },
      },
      {
        path: "aftersale",
        name: "aftersale",
        component: () => import("@/views/sopping/afterSale"),
        meta: { title: "售后管理" },
      },
      {
        path: "generalproblem",
        name: "generalproblem",
        component: () => import("@/views/sopping/generalProblem"),
        meta: { title: "通用问题" },
      },
      {
        path: "keyword",
        name: "keyword",
        component: () => import("@/views/sopping/keyWord"),
        meta: { title: "关键词" },
      },
    ],
  },
  {
    path: "/product",
    component: Layout,
    redirect: "/product/commoditylist",
    name: "product",
    meta: { title: "商品管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "commoditylist",
        name: "commoditylist",
        component: () => import("@/views/product/commodityList"),
        meta: { title: "商品列表" },
      },
      {
        path: "merchandiseshelf",
        name: "merchandiseshelf",
        component: () => import("@/views/product/merchandiseShelf"),
        meta: { title: "商品上架" },
      },
      {
        path: "productreview",
        name: "productreview",
        component: () => import("@/views/product/productReview"),
        meta: { title: "商品评论" },
      },
    ],
  },
  {
    path: "/extend",
    component: Layout,
    redirect: "/extend/advertisingmanagement",
    name: "extend",
    meta: { title: "推广管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "advertisingmanagement",
        name: "advertisingmanagement",
        component: () => import("@/views/extend/advertisingManagement"),
        meta: { title: "广告管理" },
      },
      {
        path: "couponmanagement",
        name: "couponmanagement",
        component: () => import("@/views/extend/couponManagement"),
        meta: { title: "优惠券管理" },
      },
      {
        path: "cardadd",
        name: "cardadd",
        component: () => import("@/views/extend/cardadd"),
        meta: { title: "优惠券详情" },
        hidden: true,

      },
      {
        path: "thematicmanagement",
        name: "thematicmanagement",
        component: () => import("@/views/extend/thematicManagement"),
        meta: { title: "专题管理" },
      },
      {
        path: "artadd",
        name: "artadd",
        component: () => import("@/views/extend/artadd"),
        meta: { title: "专题编辑" },
        hidden: true,
      },
      {
        path: "groupbuying",
        name: "groupbuying",
        component: () => import("@/views/extend/groupBuying"),
        meta: { title: "团购规则" },
      },
      {
        path: "groupbuyingactivity",
        name: "groupbuyingactivity",
        component: () => import("@/views/extend/groupBuyingActivity"),
        meta: { title: "团购活动" },
      },
    ],
  },
  {
    path: "/systemmanagement",
    component: Layout,
    redirect: "/systemmanagement/adminIstrator",
    name: "systemmanagement",
    meta: { title: "系统管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "adminIstrator",
        name: "adminIstrator",
        component: () => import("@/views/systemmanagement/adminIstrator"),
        meta: { title: "管理员" },
      },
      {
        path: "notificationmanagement",
        name: "notificationmanagement",
        component: () =>
          import("@/views/systemmanagement/notificationManagement"),
        meta: { title: "通知管理" },
      },
      {
        path: "operationlog",
        name: "operationlog",
        component: () => import("@/views/systemmanagement/operatioLog.vue"),
        meta: { title: "操作日志" },
      },
      {
        path: "rolemanagement",
        name: "rolemanagement",
        component: () => import("@/views/systemmanagement/roleManagement"),
        meta: { title: "角色管理" },
      },
      {
        path: "objectstorage",
        name: "objectstorage",
        component: () => import("@/views/systemmanagement/objectStorage"),
        meta: { title: "对象存储" },
      },
    ],
  },
  {
    path: "/configurationmanagement",
    component: Layout,
    redirect: "/configurationmanagement/shoppingconfig",
    name: "configurationmanagement",
    meta: { title: "配置管理", icon: "el-icon-s-data" },
    children: [
      {
        path: "shoppingconfig",
        name: "shoppingconfig",
        component: () =>
          import("@/views/configurationmanagement/shoppingConfig"),
        meta: { title: "商场配置" },
      },
      {
        path: "freightallocation",
        name: "freightallocation",
        component: () =>
          import("@/views/configurationmanagement/freightAllocation"),
        meta: { title: "运费配置" },
      },
      {
        path: "orderallocation",
        name: "orderallocation",
        component: () =>
          import("@/views/configurationmanagement/orderAllocation"),
        meta: { title: "订单配置" },
      },
      {
        path: "programconfiguration",
        name: "programconfiguration",
        component: () =>
          import("@/views/configurationmanagement/programConfiguration"),
        meta: { title: "小程序配置" },
      },
    ],
  },
  {
    path: "/statistics",
    component: Layout,
    redirect: "/statistics/userStatistics",
    name: "statistics",
    meta: { title: "统计报表", icon: "el-icon-s-data" },
    children: [
      {
        path: "userStatistics",
        name: "userStatistics",
        component: () => import("@/views/statistics/userStatistics"),
        meta: { title: "用户统计" },
      },
      {
        path: "orderStatistics",
        name: "orderStatistics",
        component: () => import("@/views/statistics/orderStatistics"),
        meta: { title: "订单统计" },
      },
      {
        path: "product2",
        name: "product2",
        component: () => import("@/views/statistics/product"),
        meta: { title: "商品统计" },
      },
    ],
  },
  {
    path: 'external-link',
    component: Layout,
    meta: { title: '外链', icon: 'link' },
    children: [
      {
        path: 'https://cloud.tencent.com/product/cos',
        meta: { title: '腾讯云存储', icon: 'link' }
      },
      {
        path: 'https://cloud.tencent.com/product/sms',
        meta: { title: '腾讯云短信', icon: 'link' }
      },
      {
        path: 'https://pay.weixin.qq.com/index.php/core/home/login',
        meta: { title: '微信支付', icon: 'link' }
      },
      {
        path: 'https://mpkf.weixin.qq.com/',
        meta: { title: '小程序客服', icon: 'link' }
      },
      {
        path: 'https://www.alibabacloud.com/zh/product/object-storage-service?_p_lc=1',
        meta: { title: '阿里云存储', icon: 'link' }
      },
      {
        path: 'https://www.qiniu.com/products/kodo',
        meta: { title: '七牛云存储', icon: 'link' }
      },
      {
        path: 'https://www.kdniao.com/api-track',
        meta: { title: '快递鸟', icon: 'link' }
      },
  ]
},

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
